package gui;

import java.util.Calendar;
import java.util.Date;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import midlet.MidletCielsa;
import rms.SesionRMS;
import util.CommandBuilder;

/**
 *
 * @author Dikas
 */
public class FrmSaludo extends Form implements CommandListener {
    
    private StringItem strMensaje;
    private Command cmdOk;
    private MidletCielsa midlet;
    private Displayable previousDisplayable;
    
    public FrmSaludo(MidletCielsa midlet, Displayable previousDisplayable) {
        super("Saludo");
        
        this.midlet = midlet;
        this.previousDisplayable =previousDisplayable;
                
        SesionRMS sesionRMS = new SesionRMS();        
        strMensaje = new StringItem("Bienvenido:", sesionRMS.getNombre() + " " + sesionRMS.getApellidoPaterno() + " " + sesionRMS.getApellidoMaterno());
        cmdOk = CommandBuilder.getOk();
        append(strMensaje);
        addCommand(cmdOk);
        setCommandListener(this);
    }
    
    public void commandAction(Command c, Displayable d) {
        if (c == cmdOk) {
            SesionRMS rms = new SesionRMS();
            String strFecha = rms.getFecha();            
            String strHoy = ""+Calendar.YEAR+Calendar.MONTH+Calendar.DAY_OF_MONTH;
            if(strFecha.compareTo(strHoy)!=0){
                rms.setFecha(strHoy);
                midlet.setDisplay(new FrmSincronizando(midlet, previousDisplayable));
            }
            else
            {
                midlet.setDisplay(new LstMenu(midlet));
            }            
        }
    }
}
